#include "KeyManager.h"

#include "OgreFrameWork.h"

KeyManager::KeyManager()
{
    //ctor
    addKey("moveCameraLeft", OIS::KC_LEFT);
    addKey("moveCameraRight", OIS::KC_RIGHT);
    addKey("moveCameraUp", OIS::KC_UP);
    addKey("moveCameraDown", OIS::KC_DOWN);
}

KeyManager::~KeyManager()
{
    //dtor
}


KeyManager* KeyManager::getInstance()
{
    static KeyManager* instance = 0;
    if (!instance) instance = new KeyManager();
    return instance;
}

/** @brief addKey
  *
  * @todo: document this function
  */
void KeyManager::addKey(std::string _action, OIS::KeyCode _keyCode)
{
   // if (m_keyMap.count(_action)<1)
        m_keyMap.insert(std::pair<std::string, OIS::KeyCode>(_action, _keyCode));
        OgreFramework::getSingletonPtr()->m_pLog->logMessage("add key action : "+_action);
}

/** @brief getKeyCode
  *
  * @todo: document this function
  */
OIS::KeyCode KeyManager::getKeyCode(std::string _name)
{
    if (m_keyMap.count(_name)>0)
    {
        //OgreFramework::getSingletonPtr()->m_pLog->logMessage("return key for : "+_name);
        return m_keyMap[_name];
    }
    else
    {


        OgreFramework::getSingletonPtr()->m_pLog->logMessage("ERROR : no key assigned to this action");
        return OIS::KC_YEN;
    }
}

